#include "BlockQueue.hpp"
#include "Task.hpp"

void *Conusumer(void * arg)
{
  //auto bq = (BlockQueue<int>*)arg;
  auto bq = (BlockQueue<Task>*)arg;
  while(true){
    sleep(1);
    //int data = 0;
    //bq->Pop(data);
    //cout<<"consumer : "<< data <<endl;
    Task t;
    bq->Pop(t);
    t.Run();
  }
}

void* Producter(void * arg)
{
  //auto bq = (BlockQueue<int>*)arg;
  auto bq = (BlockQueue<Task>*)arg;
  const char *arr = "+-*/";
  while(true){
    //sleep(1);
    int x = rand()%100 + 1;
    int y = rand()%150;
    char op = arr[rand()%4];
    Task t(x,y,op);
    //int data = rand()%100 + 1;
    //bq->Push(data);//
    bq->Push(t);
    //cout << "producer :" << data << endl;
    //cout << "producer "<< endl;
  }
}

int main()
{
  srand((unsigned long)time(nullptr));
  //BlockQueue<int> *bq = new BlockQueue<int>();
  BlockQueue<Task> *bq = new BlockQueue<Task>();

  pthread_t c, p;
  pthread_create(&c, nullptr, Conusumer, bq);
  pthread_create(&c, nullptr, Producter, bq);

  pthread_join(c, nullptr);
  pthread_join(p, nullptr);

  return 0;

}
